<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Order extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	function __construct()
	 {
		parent::__construct();
		$this->load->model('Function_m','fun');
		$this->load->model('Order_m','m');
		$this->pageSize =$this->config->item('pagenum');
	 }

	public function index()
	{
		$this->tpl->display("product/welcome.tpl");
	}
	/*********
	*** 订单搜索脚本配置列表
	***
	****************/
	function ordersearchlist()
	{
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
        $where = "";
		$list = $this->fun->getalllist("db_order_search", $where, $nowpage, $if_csv, $this->pageSize, $orderby);
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
        $this->tpl->assign("orderlist", $list["list"]);
		$this->tpl->display("order/ordersearchlist.tpl");
	}

	/********************
	*** 货运方式设置
	***
	****************/
	public function expresstype()
	{
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
        $where = "";
		$list = $this->fun->getalllist("db_order_express", $where, $nowpage, $if_csv, $this->pageSize, $orderby);
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
        $this->tpl->assign("orderlist", $list["list"]);
		$this->tpl->display("order/expresstype.tpl");
	}
	/*********
	*** 订单搜索脚本配置
	***
	****************/
	public function addordersearch()
	{
		$id = intval($this->input->get('id'));
		if($id){
			$res = $this->fun->getdatabasesdetail("db_order_search"," AND id='".$id."'");
			if($res["orderstatus"])
			{
				$res["orderstatus"] = explode(",",$res["orderstatus"]);
			}
			if($res["warehouseId"])
			{
				$res["warehouseId"] = explode(",",$res["warehouseId"]);
			}else{
				$res["warehouseId"]  = array();
			}
		}else{
			$res["orderstatus"]  = array();
			$res["warehouseId"]  = array();
		}
		$express = $this->db->get_where("db_order_express","status=0")->result_array();
		//发货仓库
		$warehouse = $this->db->get_where("db_storage","isdel=0")->result_array();
		$this->tpl->assign("warehouse",$warehouse);
		$this->tpl->assign("express",$express);
		$this->tpl->assign("detail",$res);
		$this->tpl->display("order/addordersearch.tpl");
	}
	/*********
	*** 添加货运方式
	****************/
	public function addexpresstype()
	{
		$showlistxy= "";
		$id = intval($this->input->get('id'));
		if($id){
			$res = $this->fun->getdatabasesdetail("db_order_express"," AND id='".$id."'");
			$this->tpl->assign("detail",$res);

			if($res["types"]==3)
			{
				$ibei=0.1;
				$endsum = 5;
			}
			else{
				$ibei=0.5;
				$endsum = 20;
			}


			
	
			$listexpress = $this->db->get_where("db_order_express_formula"," expresstypeid='".$id."'")->result_array();
			$this->tpl->assign("listexpress",$listexpress);
			if(count($listexpress)>0)
			{
				foreach($listexpress as $key=>$rs)
				{
					if($rs["area"] == 1 && $rs["country"]) $country1 = $rs["country"];
					if($rs["area"] == 2 && $rs["country"]) $country2 = $rs["country"];
					if($rs["area"] == 3 && $rs["country"]) $country3 = $rs["country"];
					if($rs["area"] == 4 && $rs["country"]) $country4 = $rs["country"];
					if($rs["area"] == 5 && $rs["country"]) $country5 = $rs["country"];
					if($rs["area"] == 6 && $rs["country"]) $country6 = $rs["country"];
					if($rs["area"] == 7 && $rs["country"]) $country7 = $rs["country"];
					if($rs["area"] == 8 && $rs["country"]) $country8 = $rs["country"];
					if($rs["area"] == 9 && $rs["country"]) $country9 = $rs["country"];

					$listexpressprice = $this->db->get_where("db_order_express_formula_price"," formula_id='".$rs["id"]."'")->result_array();
					if(count($listexpressprice)>0)
					{
						$showlistxy = 1;
					}
					
				}

				
			}
			$listxy=' <table cellpadding="0" cellspacing="0" border="0" class="stdtable">';
			$listxy.=' <tr><td>weight(KG)</td><td>1区<input type="hidden" name="title[]" value="'.$res['name'].'1区"/><input type="hidden" name="area[]" value="1" /></td><td>2区<input type="hidden" name="title[]" value="'.$res['name'].'2区"/><input type="hidden" name="area[]" value="2" /></td> <td>3区<input type="hidden" name="title[]" value="'.$res['name'].'3区"/><input type="hidden" name="area[]" value="3" /></td><td>4区<input type="hidden" name="title[]" value="'.$res['name'].'4区"/><input type="hidden" name="area[]" value="4" /></td><td>5区<input type="hidden" name="title[]" value="'.$res['name'].'5区"/><input type="hidden" name="area[]" value="5" /></td><td>6区<input type="hidden" name="title[]" value="'.$res['name'].'6区"/><input type="hidden" name="area[]" value="6" /></td><td>7区<input type="hidden" name="title[]" value="'.$res['name'].'7区"/><input type="hidden" name="area[]" value="7" /></td><td>8区<input type="hidden" name="title[]" value="'.$res['name'].'8区"/><input type="hidden" name="area[]" value="8" /></td><td>9区<input type="hidden" name="title[]" value="'.$res['name'].'9区"/><input type="hidden" name="area[]" value="9" /></td></tr>';
			$listxy.=' <tr><td>设置国家</td><td><input name="country[]" value="'.$country1.'" type="text" id="countryid1" class="width100"><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(1);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country2.'"  type="text" id="countryid2" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(2);"><span>编辑</span></a></td> <td><input name="country[]"  type="text" id="countryid3" value="'.$country3.'" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(3);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country4.'"  type="text" id="countryid4" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(4);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country5.'" type="text" id="countryid5" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(5);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country6.'" type="text" id="countryid6" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(6);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country7.'" type="text" id="countryid7" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(7);"><span>编辑</span></a></td><td><input name="country[]"  type="text" id="countryid8" value="'.$country8.'" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(8);"><span>编辑</span></a></td><td><input name="country[]" value="'.$country9.'"  type="text" id="countryid9" class="width100" ><a style="cursor: pointer;" class="d_blue"  onclick="return selectCountry(9);"><span>编辑</span></a></td></tr>';
			if($showlistxy==1)
			{
				$i=$ibei;
				$s=1;
				while($i<=$endsum) {
					$ht = $i*1000;
				$listxy.=' <tr>';
				$listxy.=' <td>'.$i.'<input type="hidden" name="baseweight[]" value="'.$ht.'"/></td>';
				$resdb = $this->db->get_where("db_order_express_formula_price","weight='".$ht."' AND expresstypeid='".$id."'")->result_array();
				foreach($resdb as $key=>$rs)
				{
					 if($rs["price"]=='0.00')$rs["price"]='';
					 $listxy.='<td><input type="text" size="10" name="basemoney'.$s.'[]" value="'.$rs["price"].'"  class="width100" /></td>';
				}
				$listxy.='</tr>';
				$i=$i+$ibei;
				$s=$s+1;
				}
			}else{
				$i=$ibei;
				$s=1;
				while($i<=$endsum) {
					$inum = $i*1000;
					$listxy.='<tr><td>'.$i.'<input type="hidden" name="baseweight[]" value="'.$inum.'"/></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td><td><input type="text" size="10" name="basemoney'.$s.'[]"  class="width100" /></td></tr>';
					$i=$i+$ibei;
					$s=$s+1;
				}
			}
			$listxy.="</table>";
			$this->tpl->assign("listxy",$listxy);
			
		}

		$this->tpl->display("order/addexpresstype.tpl");
	}
	/*********
	*** 保存货运方式
	*** // 
	****************/
	public function saveexpresstype()
	{
		$this->m->saveexpresstype();
		if($this->input->post("id"))
			$this->fun->phpalert(4, "", '', "/order/addexpresstype?id=".intval($this->input->post("id")));
		else
			$this->fun->phpalert(4, "", '', "/order/expresstype");

	}
	/*********
	*** 订单设置
	*** // 
	****************/
	public function orderset()
	{
		$rsdb = $this->fun->getconfig();
		$this->tpl->assign("rsdb",$rsdb);
		$this -> tpl -> display("order/syscenter.tpl");
	}
	/*********
	*** 保存订单搜索脚本配置
	*** // customerreserve2 in('加拿大','美国','墨西哥','新加坡') and shoptypeid not in('17','63','64','65') and nvl(orderweight,0) between 2000 and 4000  and status in('已支付') and ordertime >= sysdate - 30and nvl(moneyexpressask,0) between '0' and '119'
	****************/
	public function saveordersearch()
	{
		$this->m->saveordersearch();
		$this->fun->phpalert(4, "", '', "/order/ordersearchlist");
	}
	/*********
	*** FBA订单信息修改
	***
	****************/
	function editFBAorder()
	{
		$order_id = intval($this->input->get('order_id'));
		$detail = $this->fun->getdatabasesdetail("db_amzordertmp ", " AND id='" . $order_id . "'");
		
		if($_COOKIE["classid"]==14)
		{
			$shopname = $_COOKIE["shopname"];	//开通了权限的人员需要绑定店铺
			$shopname = unserialize($shopname);
			if(!in_array($detail["shopname"],$shopname))
			{
				die('E');
			}
		}
		
		
	

		$deliverprice   = 0;
		/*商品信息*/
        $goodslist = $this->fun->getdatabaseslist("db_amzordertmpsell A left join db_goods B ON A.productid=B.goods_sku", " AND ordertmpid='" . $order_id . "' "," A.*,B.goods_name,B.goods_id as bgoods_id ");
		 foreach ($goodslist as $key => $rs) {
                $acostprice = 0;
				
				if($rs["goods_id"]){
                $goods_images = $this->db->get_where('db_goods_images', 'goods_id=' . $rs["goods_id"])->result_array();
                $thumb_url = $goods_images[0]["thumb_url"];
                if ($thumb_url) {
                    $goodslist[$key]["thumb_url"] = $thumb_url;
                    $goodslist[$key]["local_url"] = $goods_images[0]["local_url"];
                } else {
                    $goodslist[$key]["thumb_url"] = "/fuman/images/s-l500.jpg";
                }
				}

				$goodslist[$key]["onecostprice"] =round( $rs['costprice'] / $rs['ordernum']);

				
				
				if($rs["deliverprice"]==0)
				{
					$derprice = $this->fun->get_oversea_express_costprice(trim($rs['productid']),$detail['shopname']);
				}else{
					$derprice = $rs["deliverprice"];
				}
				$deliverprice = $deliverprice+$derprice*$rs['ordernum'];

				$goodslist[$key]["deliverprice"] = $derprice;//头程费用
		 }
	
			//总收入
			$detail['totalgoods_amount'] = $detail['goods_amount']+$detail['shipping_fee'];
		//商品成本
			$totalcostprice = 0;
			
			$payship_fee	= 0;
			$goodsList = $this->fun->getdatabaseslist('db_amzordertmpsell '," AND ordertmpid='".$order_id."'","goods_id,productid,ordernum,costprice,(costprice) as totalcostprice"); 
			foreach($goodsList as $k=>$rd)
			{
				$totalcostprice = $totalcostprice+$rd['totalcostprice'];
			}
			
			$refundMoney = round($detail['refundMoney']*$detail['moneyrate'],2);
			$detail["refundMoneyRMB"] = $refundMoney;
			$payship_fee = $detail['payship_fee'] +$refundMoney;//FBA费用，如果有退款，需要加上退款费用

			
			$detail["totalcostprice"] = $totalcostprice;
			$detail['allcostprice'] = $totalcostprice+$deliverprice - $detail['payship_fee'];

			if($detail['status'] == 1)
			{
				$profits = $detail['totalgoods_amount'] - $totalcostprice - $deliverprice + $detail['payship_fee'];
				$detail["profits"] = round($profits,2);//利润
			}
			if($detail['status'] == 3)	//退款
			{
				$profits = $detail['totalgoods_amount']  + $payship_fee;
				$detail["profits"] = round($profits,2);//利润
			}
			if($detail['status'] == 2)	//退款
			{
				$detail["profits"] = 0;//利润
			}



		

		$this->tpl->assign("detail", $detail);
		$this->tpl->assign("goodslist", $goodslist);
		$this->tpl->display("order/editFBAorder.tpl");
	}

	function amazonfba()
	{
		//更新已经存在的SKU
		
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
		if($this->input->get('isall')==1)
		{
		
		}else{
			$status = $this->input->get('status');
			if($status)
			{
			$where = " AND status=$status";
				if($status==2)
				{
					$this->m->getorderisok();
				}
			$this->tpl->assign("status", $status);
			}
		}
		
		if($this->input->get_post('shopid'))
		{
			$where.=" AND shopid = ". intval($this->input->get_post('shopid'));
			$this->tpl->assign("shopid", intval($this->input->get_post('shopid')));
		}
		
		if ($this->input->get_post('other')) {
            $other = trim($this->input->get_post('other'));
            if (strstr($other, ",")) {
                $others = explode(",", $other);
                $where .= " and (";
                foreach ($others as $key => $r) {
                    if ($key > 0) $k = "or";
                    $where .= " $k tradeid='".$r."'" ;
                }
                $where .= ")";

            } else {
                $where .= " and  (
					 tradeid =   '" . $other . "'
					) ";
            }
            $this->tpl->assign("other", trim($this->input->get_post('other')));
        }
		if($this->input->get_post('kw'))
		{
			 $goodsku = trim($this->input->get_post('kw'));
			 $this->tpl->assign("goodsku",$goodsku);
			 $dbname = " LEFT JOIN db_amzordertmpsell B ON A.id = B.ordertmpid";
			 $where.=" AND B.productid like '%".$goodsku."%'";
		}

		if($this->input->get_post('goods_id'))
		{
			 $goods_id = trim($this->input->get_post('goods_id'));
			 $this->tpl->assign("goods_id",$goods_id);
			 $dbname = " LEFT JOIN db_amzordertmpsell B ON A.id = B.ordertmpid";
			 $where.=" AND B.goods_id = '".$goods_id."'";
		}

		if($this->input->get_post('st'))
		{
			
			$where.=" AND fulfillmentchannel = '". trim($this->input->get_post('st'))."'";
			$this->tpl->assign("status", trim($this->input->get_post('st')));
		}

		if($this->input->get_post('ty'))
		{
			if($this->input->get_post('ty')==1) $tys= "ordercreatetime";
			if($this->input->get_post('ty')==2) $tys= "dates";

			
			$this->tpl->assign("ty", trim($this->input->get_post('ty')));
		}
		
		

		$starttime = trim($this->input->get('starttime'));
			if ($starttime) {
				$times = $starttime . " 00:00:00";
				$where .= " AND ($tys >= '" . $times . "')";
				$this->tpl->assign("starttime", $starttime);
			}

			$endtime = trim($this->input->get('endtime'));
			if ($endtime) {
				$times = $endtime . " 23:59:59";
				$where .= " AND ($tys <= '" . $times. "')";
				$this->tpl->assign("endtime", $endtime);
			}
		if($this->input->get('orderby'))
		{
			$orderbyst = $this->input->get('orderby');
			if($orderbyst ==1)
			{
				$orderby = " order by A.orderTime ASC";
				$this->tpl->assign("orderbyst",2);
			}else{
				$orderby = " order by A.orderTime DESC";
				$this->tpl->assign("orderbyst",1);
			}
		}else{
			$orderby = " order by A.id DESC";
			$this->tpl->assign("orderby",1);
		}

		
		/*查询绑定的店铺订单**/
		if($_COOKIE["department"] ==1)
		{
			
		}else{
			$where.=$this->fun->getshopnameauth();
		}
		
        $list = $this->fun->getalllist("db_amzordertmp A $dbname", $where, $nowpage, $if_csv, $this->pageSize, $orderby,"A.*");
		
		foreach($list["list"] as $key=>$rs)
		{
			$shop =  $this->fun->getdatabasesdetail("d_shop"," AND name='".$rs["shopname"]."'");	//负责人
			$list["list"][$key]["responsible"] = $shop["updateoper"];
			$list["list"][$key]["platfromname"] = $shop["platfromname"];

			//商品成本
			$totalcostprice = 0;
			$deliverprice   = 0;
			$payship_fee	= 0;
			$goodsList = $this->fun->getdatabaseslist('db_amzordertmpsell '," AND ordertmpid='".$rs['id']."'","goods_id,productid,ordernum,costprice,( costprice) as totalcostprice,deliverprice"); 
			foreach($goodsList as $k=>$rd)
			{
				$totalcostprice = $totalcostprice+$rd['totalcostprice'];
				if($rd["deliverprice"]==0)
				{
					$derprice = $this->fun->get_oversea_express_costprice(trim($rd['productid']),$rs['shopname']);
				}else{
					$derprice = $rd["deliverprice"];
				}
				$deliverprice = $deliverprice+($derprice*$rd["ordernum"]);

			}
			$list["list"][$key]['totalgoods_amount'] = $totalgoods_amount = $rs['goods_amount']+$rs['shipping_fee'];
			$refundMoney = round($rs['refundMoney']*$rs['moneyrate'],2);
			$payship_fee = $rs['payship_fee'] +$refundMoney;
			$list["list"][$key]["payship_fee"] = $payship_fee;//FBA费用，如果有退款，需要加上退款费用

			$list["list"][$key]["totalcostprice"] = $totalcostprice;
			$list["list"][$key]["deliverprice"] = $deliverprice;//头程费用
			
			if($rs['status'] == 1)
			{
				$profits = $totalgoods_amount - $totalcostprice - $deliverprice + $rs['payship_fee'];
				$list["list"][$key]["profits"] = round($profits,2);//利润
			}
			if($rs['status'] == 3)	//退款
			{
				$profits = $totalgoods_amount  + $payship_fee;
				$list["list"][$key]["profits"] =round($profits,2);//利润
			}
			if($rs['status'] == 2)	//退款
			{
				$list["list"][$key]["profits"] = 0;//利润
			}
			
			
		}
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
		$this->tpl->assign("d_shop", $this->fun->getdatabaseslist('d_shop'," AND openflag= 1 AND platfromname='Amazon'",'id,name',' order by name asc'));			//查所有店铺
        $this->tpl->assign("orderlist", $list["list"]);

		$this->tpl->assign('st',date("Y-m-d"));
		$current = $this->input->get('current')? $this->input->get('current'):0;
		$this->tpl->assign('current',$current);

        $this->tpl->display("order/amazonfba.tpl");
	}


	function fulflllment()
	{
		//更新已经存在的SKU
		
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
	
		
		if($this->input->get_post('shopid'))
		{
			$where.=" AND shopid = ". intval($this->input->get_post('shopid'));
			$this->tpl->assign("shopid", intval($this->input->get_post('shopid')));
		}
		if($this->input->get_post('goods_id') ==99)
		{
			$where.=" AND goods_id = 0";
		}
		
		
		if($this->input->get_post('kw'))
		{
			 $goodsku = trim($this->input->get_post('kw'));
			 $this->tpl->assign("goodsku",$goodsku);
			 $where.=" AND (sku like '%".$goodsku."%' or fnsku like '%".$goodsku."%' or shipment_id like '%".$goodsku."%'  or fulfillment_center_id like '%".$goodsku."%')";

		}

		

		$starttime = trim($this->input->get('starttime'));
			if ($starttime) {
				$where .= " AND (fulflllment_data >= '" . $starttime . "')";
				$this->tpl->assign("starttime", $starttime);
			}

			$endtime = trim($this->input->get('endtime'));
			if ($endtime) {
				$where .= " AND (fulflllment_data<= '" . $endtime. "')";
				$this->tpl->assign("endtime", $endtime);
			}
		

		
		/*查询绑定的店铺订单**/
		if($_COOKIE["department"] ==1)
		{
			
		}else{
			$where.=$this->fun->getshopnameauth();
		}
		
        $list = $this->fun->getalllist("db_fba_fulflllment A $dbname", $where, $nowpage, $if_csv, $this->pageSize, $orderby,"A.*");
		
		foreach($list["list"] as $key=>$rs)
		{
			

			
		}
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
		$this->tpl->assign("d_shop", $this->fun->getdatabaseslist('d_shop'," AND openflag= 1 AND platfromname='Amazon'",'id,name',' order by name asc'));			//查所有店铺
        $this->tpl->assign("orderlist", $list["list"]);

		$this->tpl->assign('st',date("Y-m-d"));
		$current = $this->input->get('current')? $this->input->get('current'):0;
		$this->tpl->assign('current',$current);

        $this->tpl->display("order/fulflllment.tpl");
	}



	function amazoncancel()
	{
		$nowpage = $_REQUEST["pageid"];
        if ($nowpage == "") $nowpage = 1;
		
		
		if($this->input->get_post('shopid'))
		{
			$where.=" AND shopid = ". intval($this->input->get_post('shopid'));
			$this->tpl->assign("shopid", intval($this->input->get_post('shopid')));
		}
		
		if ($this->input->get_post('other')) {
            $other = trim($this->input->get_post('other'));
            if (strstr($other, ",")) {
                $others = explode(",", $other);
                $where .= " and (";
                foreach ($others as $key => $r) {
                    if ($key > 0) $k = "or";
                    $where .= " $k tradeid='".$r."'" ;
                }
                $where .= ")";

            } else {
                $where .= " and  (
					 tradeid =   '" . $other . "'
					) ";
            }
            $this->tpl->assign("other", trim($this->input->get_post('other')));
        }
	

		if($this->input->get_post('ty'))
		{
			if($this->input->get_post('ty')==1) $tys= "ordertime";
			if($this->input->get_post('ty')==2) $tys= "add_time";
			if($this->input->get_post('ty')==3) $tys= "report_time";

			
			$this->tpl->assign("ty", trim($this->input->get_post('ty')));
		}
		
		

		$starttime = trim($this->input->get('starttime'));
			if ($starttime) {
				if($this->input->get_post('ty')==2)
					$times =strtotime( $starttime . " 00:00:00");
				else
					$times = $starttime . " 00:00:00";
				
				$where .= " AND ($tys >= '" . $times . "')";
				$this->tpl->assign("starttime", $starttime);
			}

			$endtime = trim($this->input->get('endtime'));
			if ($endtime) {
				if($this->input->get_post('ty')==2)
					$times =strtotime( $endtime . " 23:59:59");
				else
					$times = $endtime . " 23:59:59";
				
				$where .= " AND ($tys <= '" . $times. "')";
				$this->tpl->assign("endtime", $endtime);
			}
		if($this->input->get('orderby'))
		{
			$orderbyst = $this->input->get('orderby');
			if($orderbyst ==1)
			{
				$orderby = " order by A.orderTime ASC";
				$this->tpl->assign("orderbyst",2);
			}else{
				$orderby = " order by A.orderTime DESC";
				$this->tpl->assign("orderbyst",1);
			}
		}else{
			$orderby = " order by A.id DESC";
			$this->tpl->assign("orderby",1);
		}

		
        $list = $this->fun->getalllist("db_amzordertmp_cancel A $dbname", $where, $nowpage, $if_csv, $this->pageSize, $orderby,"A.*");
		
		foreach($list["list"] as $key=>$rs)
		{
			
		
				$list["list"][$key]["add_time"] = date("Y-m-d H:i:s",$rs['add_time']);//利润
			
			
		}
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
		$this->tpl->assign("d_shop", $this->fun->getdatabaseslist('d_shop'," AND openflag= 1 AND platfromname='Amazon'",'id,name',' order by name asc'));			//查所有店铺
        $this->tpl->assign("orderlist", $list["list"]);

		$this->tpl->assign('st',date("Y-m-d"));
		$current = $this->input->get('current')? $this->input->get('current'):0;
		$this->tpl->assign('current',$current);

        $this->tpl->display("order/amazoncancel.tpl");
	}


	public function ajaxbutton(){
		$op = $_REQUEST["op"];
		if($op=='sfexpressurl')
		{
				
			$id = $this->input->get('id');
			/***************************
			*** 顺丰 标签打印
			****************************/
			if($this->input->get('orderType') == 1){	//顺丰打印
			//判断是批量还是单个
				if(strpos($id,',') === false){
					$orderinfo = $this->db->get_where('db_mabangorder',"id ='".$id."'")->result_array();
					$orderinfo = $orderinfo[0];

					if($orderinfo["isform"]==1){
						$goodslist = $this->db->get_where('db_mabangsell',"orderid ='".$orderinfo["orderID"]."'")->result_array();
					}else{
						$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn ='".$orderinfo["orderID"]."'");
						$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$order['order_id']."'")->result_array();
						if(count($goodslist)>0)
								{
									foreach($goodslist as $s=>$rdbs)
									{
										$goodslist[$s]['shopname'] = $order["shopname"];
										$goodslist[$s]['tradeid'] = $order["tradeid"];
										$goodslist[$s]['content1'] = $order["remark"];

										$rsstock = $this->fun->getdatabasesdetail("db_goods_stock"," AND goods_id ='".$rdbs["goods_id"]."'");
										$goodslist[$s]['stock'] = $rsstock["stock"];
										$goodslist[$s]['locationad'] = $rsstock["positions"];

									}
								}
					}
					
					$this->tpl->assign("goodslist",$goodslist);
					$this->tpl->assign("orderinfo",$orderinfo);
					$this->tpl->display("order/sfexpressurl.tpl",0,0,1);
				}else{
					$id = substr($id,0,-1);
					$inid = explode(",",$id);
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();
					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{
							if($rs["isform"]==1){
								$goodslist = $this->db->get_where('db_mabangsell',"orderid ='".$rs["orderID"]."'")->result_array();
								$orderinfo[$key]["goodslist"] = $goodslist;
							}else{

								$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn ='".$rs["orderID"]."'");
								$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$order['order_id']."'")->result_array();
								if(count($goodslist)>0)
								{
									foreach($goodslist as $s=>$rdbs)
									{
										$goods_name = $this->fun->getdatabasesdetail("db_goods"," AND goods_id ='".$rdbs["goods_id"]."'");
										$goodslist[$s]['goods_name'] = $goods_name["goods_name"];
										$goodslist[$s]['shopname'] = $order["shopname"];
										$goodslist[$s]['tradeid'] = $order["tradeid"];
										$goodslist[$s]['content1'] = $order["remark"];

										$rsstock = $this->fun->getdatabasesdetail("db_goods_stock"," AND goods_id ='".$rdbs["goods_id"]."' AND storage_id=1");
										$goodslist[$s]['stock'] = $rsstock["stock"];
										$goodslist[$s]['locationad'] = $rsstock["positions"];

									}
								}
							
								$orderinfo[$key]["goodslist"] = $goodslist;
							}
						}
						$this->tpl->assign("orderinfo",$orderinfo);
						$this->tpl->display("order/sfexpressmoreurl.tpl",0,0,1);
					}
				}
			}
			
			/***************************
			*** UPS 标签打印
			****************************/
			if($this->input->get('orderType') == 2)
			{
				if(strpos($id,',') === false){
					echo 1;
				}else{
					$id = substr($id,0,-1);
					$inid = explode(",",$id);
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();

					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{

							$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
							if($rsOrder)
							{
								$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
							
								foreach($goodslist as $sd =>$goods)
								{
									$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."' AND storage_id=1");
									$goodslist[$sd]["stock"] = $stock;
									$goods_name = $this->fun->getdatabasesdetail("db_goods"," AND goods_id ='".$goods["goods_id"]."'");
									$goodslist[$sd]['goods_name'] = $goods_name["goods_name"];
								}
								$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
								$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
								$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
								$orderinfo[$key]["remark"] = $rsOrder["remark"];
								$orderinfo[$key]["goodslist"] = $goodslist;
							}
							
							
						}
						$this->tpl->assign("orderinfo",$orderinfo);
						$this->tpl->display("order/upsexpressmoreurl.tpl",0,0,1);//打印USP标签信息
					}
				}

			}
			/***************************
			 *** 无忧 标签打印
			 ****************************/
			if($this->input->get('orderType') == 9)
			{
				if(strpos($id,',') === false){
					echo 1;
				}else{
					if(substr($id,-1) == ',')
					{
						$id = substr($id,0,-1);
						$inid = explode(",",$id);
					}else{
						$inid = explode(",",$id);
					}
					
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();
					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{
							if($rs["isexe"]==1)
							{
								$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
								if($rsOrder)
								{
									$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
									foreach($goodslist as $sd =>$goods)
									{
										$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
										$goodslist[$sd]["stock"] = $stock;
									}
									$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
									$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
									$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
									$orderinfo[$key]["remark"] = $rsOrder["remark"];
									$orderinfo[$key]["goodslist"] = $goodslist;
									//$orderinfo[$key]["aliexpressData"] = unserialize($rs["wuyresultdata"]);
								}
							}
						}
						
						$this->tpl->assign("orderinfo",$orderinfo);
						$this->tpl->display("order/wuyexpressurl.tpl",0,0,1);//打印无忧标签信息
					}
				}

			}
         
			/***************************
			 *** 燕文 标签打印
			 ****************************/
			if($this->input->get('orderType') == 7)
			{
				if(strpos($id,',') === false){
					echo 1;
				}else{
					if(substr($id,-1) == ',')
					{
						$id = substr($id,0,-1);
						$inid = explode(",",$id);
					}else{
						$inid = explode(",",$id);
					}
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();
					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{
							//打印信息包含马帮旧系统相关信息 2015/7/7
							if($rs['isform']==1){
								$goodslist = $this->db->get_where('db_mabangsell',"orderid ='".$rs["orderID"]."'")->result_array();
								if(count($goodslist)>0){
									$weight=0;
									$goods_num = 0;
									$category = 0;
									foreach($goodslist as $sd=>$goods){
										$goodslist[$sd]['goods_name']= $goods['productname'];
										$goodslist[$sd]['goods_sn']= $goods['productid'];
										$goodslist[$sd]['goods_number']= $goods['ordernum'];
										//var_dump($goods['locationad']);exit;
										//$goodslist[$sd]["stock"]=array('positions'=>$goods['locationad']);
										$goodslist[$sd]["stock"]=$goods['locationad'];
										$orderinfo[$key]["shopname"] = $goods["shopname"];
										$goods_num = $goods_num+$goods['ordernum'];
										$category = $category+1;
									}
										$orderinfo[$key]["goodslist"] = $goodslist;
								}
								$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
								$orderinfo[$key]["goods_num"]=$goods_num;
								$orderinfo[$key]["category"]=$category;

							}else{
								$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
								if($rsOrder){
									$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
									$goods_num = 0;
									$category = 0;
									foreach($goodslist as $sd =>$goods)
									{
										$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
										//$goodslist[$sd]["stock"] = $stock;
										$goodst = $this->fun->getdatabaseslist('db_goods'," AND goods_id='".$goods["goods_id"]."'");
										$goodslist[$sd]["goods_name"] = $goodst[0]['goods_name']; //获取这个goods_name

										$goodslist[$sd]["stock"] = $stock[0]['positions'];
										$goods_num = $goods_num+$goods['goods_number'];
										$category = $category+1;
									}
									$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
									$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
									$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
									$orderinfo[$key]["mailinstime"] = date("m-d",$rs['mailinstime']);
									$orderinfo[$key]["remark"] = $rsOrder["remark"];
									$orderinfo[$key]["goodslist"] = $goodslist;
								}
								$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
								$orderinfo[$key]["goods_num"]=$goods_num;
								$orderinfo[$key]["category"]=$category;
							}
							/**
							$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
							if($rsOrder){
								$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
								$goods_num = 0;
								$category = 0;
								foreach($goodslist as $sd =>$goods)
								{
									$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
									$goodslist[$sd]["stock"] = $stock;
									$goods_num = $goods_num+$goods['goods_number'];
									$category = $category+1;
								}
								$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
								$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
								$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
								$orderinfo[$key]["mailinstime"] = date("m-d",$rs['mailinstime']);
								$orderinfo[$key]["remark"] = $rsOrder["remark"];
								$orderinfo[$key]["goodslist"] = $goodslist;
							}
							$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
							$orderinfo[$key]["goods_num"]=$goods_num;
							$orderinfo[$key]["category"]=$category;
							**/
						}
					}
					$this->tpl->assign("orderinfo",$orderinfo);
					$this->tpl->display("order/yanwenexpressmoreurl.tpl",0,0,1);//打印燕文标签信息
				}

			}
			/***************************
			 *** e邮宝线下上海 标签打印
			 ****************************/
			if($this->input->get('orderType') == 8)
			{

				if(strpos($id,',') === false){
					echo 1;
				}else{
					if(substr($id,-1) == ',')
					{
						$id = substr($id,0,-1);
						$inid = explode(",",$id);
					}else{
						$inid = explode(",",$id);
					}
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();
					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{
							//打印信息包含马帮旧系统相关信息 2015/7/7
							if($rs['isform']==1){
								$goodslist = $this->db->get_where('db_mabangsell',"orderid ='".$rs["orderID"]."'")->result_array();
								if(count($goodslist)>0){
									$weight=0;
									$goods_num = 0;
									$category = 0;
									foreach($goodslist as $sd=>$goods){
										$goodslist[$sd]['goods_name']= $goods['productname'];
										$goodslist[$sd]['goods_sn']= $goods['productid'];
										$goodslist[$sd]['goods_number']= $goods['ordernum'];
										//var_dump($goods['locationad']);exit;
										//$goodslist[$sd]["stock"]=array('positions'=>$goods['locationad']);
										$goodslist[$sd]["stock"]=$goods['locationad'];
										$orderinfo[$key]["shopname"] = $goods["shopname"];
										$goods_num = $goods_num+$goods['ordernum'];
										$category = $category+1;
									}
									$orderinfo[$key]["goodslist"] = $goodslist;
								}
								$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
								$orderinfo[$key]["goods_num"]=$goods_num;
								$orderinfo[$key]["category"]=$category;

							}else{
								$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
								if($rsOrder){
									$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
									$goods_num = 0;
									$order_weight =0;
									$order_price = 0;
									$category = 0;
									foreach($goodslist as $sd =>$goods)
									{
										$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
										//$goodslist[$sd]["stock"] = $stock;
										$goodst = $this->fun->getdatabaseslist('db_goods'," AND goods_id='".$goods["goods_id"]."'");
										$goodslist[$sd]["goods_name"] = $goodst[0]['goods_name']; //获取这个goods_name

										$goodslist[$sd]["goods_name"] = mb_substr($goodslist[$sd]["goods_name"],0,24)."<br/>".mb_substr($goodslist[$sd]["goods_name"],24);

										if($goodst[0]["goods_weight"]==0)
										{
											$goodst[0]["goods_weight"] = 400;//单位g
										}
										$weightst = $goodst[0]["goods_weight"]/1000; //重量 单位kg
										$goodslist[$sd]["goods_weight"] = $weightst;
										$goodslist[$sd]["setprice"] = 22;
										$order_weight = $order_weight+$weightst;
										$order_price = $order_price + 22;

										$goodslist[$sd]["stocknum"] = $stock[0]['stock']; //库存
										$goodslist[$sd]["stock"] = $stock[0]['positions'];
										$goods_num = $goods_num+$goods['goods_number'];
										$category = $category+1;
									}
									if($goods_num>=5&&$rs['customerqq']=='US'){
										$order_weight =0;
										$order_price = 0;
										$category = 0;
										$unit_price = round(50 / $goods_num, 2);
										$unit_weight = round(1.9 / $goods_num, 2);
										$goods_num = 0;
										foreach($goodslist as $sd =>$goods)
										{
											$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
											$goodst = $this->fun->getdatabaseslist('db_goods'," AND goods_id='".$goods["goods_id"]."'");
											$goodslist[$sd]["goods_name"] = $goodst[0]['goods_name']; //获取这个goods_name

											$goodslist[$sd]["goods_name"] = mb_substr($goodslist[$sd]["goods_name"],0,24)."<br/>".mb_substr($goodslist[$sd]["goods_name"],24);

											if($goodst[0]["goods_weight"]==0)
											{
												$goodst[0]["goods_weight"] = 400;//单位g
											}
											$weightst = $unit_weight*$goods['goods_number']; //重量 单位kg
											$goodslist[$sd]["goods_weight"] = $weightst;
											$goodslist[$sd]["setprice"] = $unit_price*$goods['goods_number'];
											$order_weight = $order_weight+$weightst;
											$order_price = $order_price + $unit_price*$goods['goods_number'];

											$goodslist[$sd]["stocknum"] = $stock[0]['stock']; //库存
											$goodslist[$sd]["stock"] = $stock[0]['positions'];
											$goods_num = $goods_num+$goods['goods_number'];
											$category = $category+1;
										}



									}
									//查询邮编

									if($rs['customerqq']=='CA'){
										$postzip = substr(trim($rs['customerzipcode']),0,1);
										$postzip = strtoupper($postzip);
										$sql = "SELECT * FROM ems_code WHERE country_code = 'CA' AND zipcode like '%{$postzip}%' ";
										$ress = $this->db->query($sql)->row_array();
									}else{
										//默认美国 其他国家没有分拣码
										$postzip = substr(trim($rs['customerzipcode']),0,3);
										$sql = "SELECT * FROM ems_code WHERE country_code = 'US' AND zipcode = '{$postzip}' ";
										$ress = $this->db->query($sql)->row_array();
									}
									//print_r($sql);exit;
									if($ress['code']){
										$orderinfo[$key]["code"] = $ress["code"];
									}else{
										$orderinfo['code'] =  "没有";
									}
									$orderinfo[$key]["consignee"] = $rsOrder["consignee"];
									$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
									$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
									$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
									$orderinfo[$key]["mailinstime"] = date("m-d",$rs['mailinstime']);
									$orderinfo[$key]["remark"] = $rsOrder["remark"];
									$orderinfo[$key]["goodslist"] = $goodslist;
									$orderinfo[$key]["shipping_id"] = $rsOrder["shipping_id"]; //47为苏州E邮宝线下
								}
								$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
								$orderinfo[$key]["goods_num"]=$goods_num;
								$orderinfo[$key]["order_weight"]=$order_weight;
								$orderinfo[$key]["order_price"]=$order_price;

								$orderinfo[$key]["category"]=$category;
							}
						}
					}
					//获取E邮宝相关参数
					if($orderinfo[0]["shipping_id"]==47){
						$ems = stripslashes($this->config->item("emsexpressset"));
						$arr_ems = unserialize($ems);
					}else{
						$ems = stripslashes($this->config->item("eofflineexpressset"));
						$arr_ems = unserialize($ems);
					}

					$this->tpl->assign("emsinfo",$arr_ems);
					$this->tpl->assign("orderinfo",$orderinfo);
					$this->tpl->display("order/emsexpressmoreurl.tpl",0,0,1);//打印E邮宝标签信息
				}

			}
			/***************************
			 *** 云途 标签打印
			 ****************************/
			if($this->input->get('orderType') == 6)
			{
				if(strpos($id,',') === false){
					echo 1;
				}else{
					if(substr($id,-1) == ',')
					{
						$id = substr($id,0,-1);
						$inid = explode(",",$id);
					}else{
						$inid = explode(",",$id);
					}
					$this->db->where_in('id', $inid);
					$this->db->order_by('id', 'DESC');
					$orderinfo = $this->db->get('db_mabangorder')->result_array();
					if(count($orderinfo)){
						foreach($orderinfo as $key=>$rs)
						{
							$rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
							if($rsOrder){
								$goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
								$goods_num = 0;
								$category = 0;
								foreach($goodslist as $sd =>$goods)
								{
									$stock = $this->fun->getdatabaseslist('db_goods_stock'," AND storage_id = 1 AND  goods_id='".$goods["goods_id"]."'");

									$goodst = $this->fun->getdatabaseslist('db_goods'," AND goods_id='".$goods["goods_id"]."'");
									$goodslist[$sd]["goods_name"] = $goodst[0]['goods_name']; //获取这个goods_name

									$goodslist[$sd]["stocknum"] = $stock[0]['stock']; //库存
									$goodslist[$sd]["stock"] = $stock;
									$goods_num = $goods_num+$goods['goods_number'];
									$category = $category+1;
								}
								$orderinfo[$key]["shopname"] = $rsOrder["shopname"];
								$orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
								$orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
								$orderinfo[$key]["mailinstime"] = date("Y-m-d H:i:s",$rs['mailinstime']); //交运时间
								$orderinfo[$key]["consignee"] = $rsOrder["consignee"]; //收件人
								$orderinfo[$key]["remark"] = $rsOrder["remark"];
								$orderinfo[$key]["goodslist"] = $goodslist;
								//显示的变量信息
								$straddress = strlen($rs["customeraddress"]);
								if($straddress<=35)
								{
									$orderinfo[$key]['address1'] = $rs["customeraddress"];
									$orderinfo[$key]['address2'] = "";
									$orderinfo[$key]['address3'] = "";
								}else{
									$orderinfo[$key]['address1'] = substr($rs["customeraddress"],0,35);
									$orderinfo[$key]['address2'] = substr($rs["customeraddress"],35,70);
									$orderinfo[$key]['address3'] = substr($rs["customeraddress"],70,105);
								}
								//手机必须为10位纯数字（如果填写的话）
								$mobile = str_replace("-","",$rs['customertel1']);
								$tel = str_replace("-","",$rs['customertel2']);
								if(strlen($mobile)){
									$orderinfo[$key]['mobile'] = substr($mobile,-10);
								}
								if(strlen($tel)){
									 $orderinfo[$key]['tel'] = substr($tel,-10);
								}
							}
							if($rs['deliver']=="云途德国专线平邮"){
								$orderinfo[$key]["deliver_code"] = "DEZXA";
								$orderinfo[$key]["letter"] = "DE";
								$orderinfo[$key]["mail_way"] = "P";
							}
							if($rs['deliver']=="云途中欧专线平邮"){ //之前使用的，目前只是查看
								$orderinfo[$key]["deliver_code"] = "EUDDPG";
								$orderinfo[$key]["letter"] = $rsOrder['country_code'];
								$orderinfo[$key]["mail_way"] = "P";
							}
							if($rs['deliver']=="云途中欧专线挂号"){ // new add 1/15
								$orderinfo[$key]["deliver_code"] = "EUDDP";
								$orderinfo[$key]["letter"] = $rsOrder['country_code'];
								$orderinfo[$key]["mail_way"] = "R";
							}
							if($rs['deliver']=="中美专线(特惠)"){ // new add 1/15
								$orderinfo[$key]["deliver_code"] = "USZXR";
								$orderinfo[$key]["letter"] = "US";
								$orderinfo[$key]["mail_way"] = "R";
							}
							if($rs['deliver']=="云途德国专线挂号"){
								$orderinfo[$key]["deliver_code"] = "DEZXR";
								$orderinfo[$key]["letter"] = "DE";
								$orderinfo[$key]["mail_way"] = "R";
							}
							if($rs['deliver']=="云途法国专线挂号"){
								$orderinfo[$key]["deliver_code"] = "FRZXR";
								$orderinfo[$key]["letter"] = "FR";
								$orderinfo[$key]["mail_way"] = "R";
							}
							if($rs['deliver']=="云途英国专线标准"){
								$orderinfo[$key]["deliver_code"] = "GBZXR";
								$orderinfo[$key]["letter"] = "GB";
								$orderinfo[$key]["mail_way"] = "R";
							}
							$orderinfo[$key]["print_img"]=explode(',',$rs['print_img']);
							$orderinfo[$key]["goods_num"]=$goods_num;
							$orderinfo[$key]["category"]=$category;
						}
					}
					//var_dump($orderinfo);exit;
					$this->tpl->assign("orderinfo",$orderinfo);
					$this->tpl->display("order/expresstemplates.tpl",0,0,1);//打印燕文标签信息
				}

			}


		}
		
		if($op=='printinvoice')
		{
		
			
			/********************************************
			* 远程PDF下载到本地
			***********************************************/
			/*$url = "http://osms.sit.sf-express.com:2080/osms/wbs/print/printOrder.pub?mailno=/uvmBI9UdKG74RJcQ6JzzA==";
			$Path = dirname(__FILE__) . "/../../uploads/11111111111-order.pdf";
			$content=file_get_contents('http://osms.sit.sf-express.com:2080/osms/wbs/print/printOrder.pub?mailno=/uvmBI9UdKG74RJcQ6JzzA==');//下载到内存
			file_put_contents($Path, $content);
			die;*/

		
			$id = $this->input->get('id');
				$id = substr($id,0,-1);
				$inid = explode(",",$id);
				$this->db->where_in('id', $inid);
				$this->db->order_by('id', 'DESC');
				$orderinfo = $this->db->get('db_mabangorder')->result_array();

				$this->tpl->assign("orderinfo",$orderinfo);
				$this->tpl->display("order/printinvoice.tpl",0,0,1);
			
					

		}
		/*********修改商品的仓位信息****************/
		if($op =='changpositions')
		{
			$postdata["positions"] = trim($this->input->post('val'));
			$rsdb = $this->fun->getdatabasesdetail('db_goods_stock'," AND id='".$this->input->post('id')."'");
			$this->db->update('db_goods_stock', $postdata, 'id=' . $this->input->post('id'));
			if(trim($this->input->post('val')) != trim($this->input->post('olddata')))
			{
				$rval = "修改库位：原库位".trim($this->input->post('olddata'))." 更新为：".trim($this->input->post('val'));
				$this->fun->goods_update_log($rsdb["goods_id"],$rval,1);	//更新商品信息
				$data["txt"] = "更新成功！";
				echo json_encode($data);
				die;
			}
		}
		/********************************************
		* 订单详细中更新商品信息
		***********************************************/
		if($op =='changgoodsno')
		{
			$newgoods_sn = trim($this->input->post('val'));//获取新商品SKU
			$rec_id = trim($this->input->post('id'));//获取订单商品列表中的ID
			$rsdb = $this->fun->getdatabasesdetail("db_goods"," AND goods_sku = '".$newgoods_sn."'");
			if(!$rsdb)
			{
				$data["txt"] = "不存在该SKU【{$newgoods_sn}】 信息,请先创建该SKU";
				$data["code"] = "201";
				echo json_encode($data);
				die;
			}
			$ordersell = $this->fun->getdatabasesdetail("db_order_sell"," AND rec_id = '".$rec_id."'");
			if($rsdb && $ordersell)
			{
				$costprice = $this->fun->get_Goods_costprice($rsdb["goods_sku"]);//获取商品成本
				$ordersell["goods_id"] = $rsdb["goods_id"];
				$ordersell["goods_name"] = $rsdb["goods_name"];
				$ordersell["goods_sn"] = $rsdb["goods_sku"];
				$ordersell["costprice"] = $costprice?$costprice:0;
				$ordersell["goods_weight"] = $rsdb["g_weight"];
				//$ordersell["originsku"] = $rsdb["goods_sku"];
			
				$this->db->update("db_order_sell",$ordersell,"rec_id=".$rec_id);
				$rval = "更换商品：原商品".trim($this->input->post('olddata'))." ->更新为：".trim($this->input->post('val'))." ->成本：".trim($costprice);
				$this->fun->goods_update_log($ordersell["order_id"],$rval,3,$this->input->post('olddata'),$this->input->post('val'));	//更新订单信息
				
				/****如果是8位定制SKU转五位，提醒仓库******/
				if($this->fun->getfactorygoodsku(trim($this->input->post('olddata'))))
				{
					$goods = trim($this->input->post('val'));	//是否是关联SKU
					if($rsdb["goods_parent_sku"] != $rsdb["goods_sku"])
					{
						//给仓库人员发送消息
						$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_id = '".$ordersell["order_id"]."'","order_sn,shipping_name");
						$randid = $this->message->getMessageNums();	//获取当前存储的条数
						$receivers_config = trim($this->config->item('sys_cang_tipsmessage'));
						$arr_receiver_config = explode("|",$receivers_config);
						foreach($arr_receiver_config as $rs)
						{
							$postMessageData["message_type"] = $this->message->getMessageType(0);	//消息提醒
							$rval = $rval." 物流方式：".$order['shipping_name'];
							$message = $_COOKIE["username"]."[".date("Y-m-d H:i:s")."]"." {$rval}";
							$message.="，订单号：{$order[order_sn]}";
							$postMessageData["message"] = $message;
							$postMessageData["message_toName"] = $rs;
							$postMessageData["isread"] =  $randid;
							$postMessageData["url"] = '/orderlist/editorder?order_id='.$ordersell["order_id"];
							$this->fun->saveMessage($postMessageData);
						}

					}

				}


				//维护重量，重新计算成本
				$this->m->recalculategoodsprice($ordersell["order_id"]);
				//判断是否缺货
				$this->load->library('Orderexpress');
				$this->orderexpress->isquehuo($ordersell["order_id"]);
				$data["txt"] = "更新成功！";
				echo json_encode($data);
			}



		}
		/********************************************
		* 订单详细中更新商品成本信息
		***********************************************/
		if($op =='changgoodsprice')
		{
			$newprice= trim($this->input->post('val'));//获取新商品SKU
			$rec_id = trim($this->input->post('id'));//获取订单商品列表中的ID
		
			$ordersell = $this->fun->getdatabasesdetail("db_order_sell"," AND rec_id = '".$rec_id."'");
			if($ordersell)
			{
				$newordersell = "";
				$newordersell["costprice"] = $newprice;
				$this->db->update("db_order_sell",$newordersell,"rec_id=".$rec_id);
				$rval = "修改成本：原商品【{$ordersell[goods_sn]}】成本 ".trim($ordersell["costprice"])." ->更新为：".trim($this->input->post('val'));
				$this->fun->goods_update_log($ordersell["order_id"],$rval,3,$ordersell["costprice"],$this->input->post('val'));	//更新订单信息
				$data["txt"] = "更新成功！";
				echo json_encode($data);
			}

		}
		/********************************************
		* 修改订单中的运费收入
		***********************************************/
		if($op =='changshippingfee')
		{
			$newprice= trim($this->input->post('val'));//获取新商品SKU
			$order_id = trim($this->input->post('id'));//获取订单ID
		
			$ordersell = $this->fun->getdatabasesdetail("db_order_list"," AND order_id = '".$order_id."'");
			if($ordersell)
			{
				$newordersell = "";
				$newordersell["shipping_fee"] = $newprice;
				//原始运费
				if($ordersell['moneyrate']>0)$newordersell["shipping_originask"] = round($newprice/$ordersell['moneyrate'],2);
				$this->db->update("db_order_list",$newordersell,"order_id=".$order_id);
				$rval = "修改运费收入：原运费 ".trim($ordersell["shipping_fee"])." ->更新为：".trim($this->input->post('val'));
				$this->fun->goods_update_log($order_id,$rval,3,$ordersell["shipping_fee"],$this->input->post('val'));	//更新订单信息
				$data["txt"] = "更新成功！";
				echo json_encode($data);
			}

		}
		/********************************************
		* 查看商品是否存在
		***********************************************/
		if($op =='getgoodssku')
		{
			$newgoods_sn = trim($this->input->get_post('val'));//获取新商品SKU
			$rsdb = $this->fun->getdatabasesdetail("db_goods"," AND goods_sku = '".$newgoods_sn."' and g_sale_status !=4 ");
			if(!$rsdb)
			{
				$data["code"] = 201;
				$data["txt"] = "商品编号【{$newgoods_sn}】信息不存在,请先添加商品信息！";
				echo json_encode($data);
				die;
			}else{
				$data["code"] = 200;
				$data["txt"] = $rsdb;
				echo json_encode($data);
				die;
			}
		}
		
		/********************************************
		* 订单详细中更新商品留言信息
		***********************************************/
		if($op =='changmessage')
		{
			$remark = trim($this->input->post('val'));//获取新商品SKU
			$rec_id = trim($this->input->post('id'));//获取订单商品列表中的ID
			$ordersell = $this->fun->getdatabasesdetail("db_order_sell"," AND rec_id = '".$rec_id."'");
			if($ordersell)
			{
				$ordersell["sale_remark"] = $remark;
				$this->db->update("db_order_sell",$ordersell,"rec_id=".$rec_id);
				$remradk = $ordersell["sale_remark"]?$ordersell["sale_remark"]:'NULL';
				$rval ="编辑留言：[$ordersell[goods_sn]]原留言".$this->input->post('olddata')." ->更新为：".trim($this->input->post('val'));
				$this->fun->goods_update_log($ordersell["order_id"],$rval,3,$this->input->post('olddata'),$this->input->post('val'));	//更新订单信息
				$data["txt"] = "更新成功！";
				echo json_encode($data);
			}
		}
		/********************************************
		* 更新工厂系统中出货记录报表备注信息
		***********************************************/
		if($op =='factoryorderremark')
		{
			$remark = addslashes(trim($this->input->post('val')));//内容
			$rec_id = trim($this->input->post('id'));//
			$this->db->update("db_factory_sell",array("remark"=>$remark),"id=".$rec_id);
			$data["txt"] = "更新成功！";
			echo json_encode($data);

		}
		/********************************************
		* 更新手动入库中的编辑备注信息
		***********************************************/
		if($op =='savememohandstock')
		{
			$remark = addslashes(trim($this->input->post('val')));//内容
			$rec_id = trim($this->input->post('id'));//
			$this->db->update("db_goods_handstorage",array("memo"=>$remark),"id=".$rec_id);
			$data["txt"] = "更新成功！";
			echo json_encode($data);

		}
		/********************************************
		* 更新申请调拨需求页面备注
		***********************************************/
		if($op =='savedeliveryplanpro')
		{
			$remark = addslashes(trim($this->input->post('val')));//内容
			$rec_id = trim($this->input->post('id'));//
			$this->db->update("t_overseapurchasing",array("remark"=>$remark),"id=".$rec_id);
			$data["txt"] = "更新成功！";
			echo json_encode($data);

		}
		/********************************************
		* 更新物料备注信息
		***********************************************/
		if($op =='factorymaterialmark')
		{
			$remark = addslashes(trim($this->input->post('val')));//内容
			$rec_id = trim($this->input->post('id'));//
			$this->db->update("db_factory_material",array("descr"=>$remark),"id=".$rec_id);
			$data["txt"] = "更新成功！";
			echo json_encode($data);

		}
		/***********************************
		** 订单详细中添加新的商品信息
		**
		***************************/
		if($op =='addgoodsno')
		{
			
			$moneyratelist = $this->input->post('moneyratelist');
			if(!$moneyratelist){
				$this->fun->phpalert(2, "请先设定货币单位");
				die;
			}
			$rate = $this->fun->getmoneyrate($moneyratelist);
			$orderID = trim($this->input->post('addgoodsorderID'));
			$ordergoodsno = $this->input->post('ordergoodsno');
			$ordergoodsnoNum = $this->input->post('ordergoodsnoNum');
			$ordergoodsnoPrice = $this->input->post('ordergoodsnoPrice');
			if($ordergoodsno)
			{
				$this->db->trans_begin();
				foreach($ordergoodsno as $key=>$goods)
				{
					$rsdb = $this->fun->getdatabasesdetail("db_goods"," AND goods_sku = '".trim($goods)."'");
					if(!$rsdb)
					{
						$this->fun->phpalert(2, "不存在该SKU信息");
						die;
					}else{
						$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_id = '".$orderID."'","moneytype,order_status,order_sn,dates");
						if($rate['rate']=='')
						{
							$rate['rate'] = $order['moneytype'];
						}
						$ordersell = "";
						$ordersell["order_id"] = $orderID;
						$ordersell["goods_id"] = $rsdb["goods_id"];
						$ordersell["goods_name"] = $rsdb["goods_name"];
						$ordersell["goods_sn"] = $rsdb["goods_sku"];

						$costprice = $this->fun->get_Goods_costprice($rsdb["goods_sku"]);
						$ordersell["costprice"] = $costprice;
						$ordersell["goods_number"] = intval($ordergoodsnoNum[$key])?intval($ordergoodsnoNum[$key]):1;
						$ordersell["goods_price"] = trim($ordergoodsnoPrice[$key])*$rate['rate'];	//人民币金额
						$originsellprice = trim($ordergoodsnoPrice[$key]);
						$ordersell["originsellprice"] = $originsellprice?$originsellprice:0.00;	//原始金额
						$ordersell["goods_amount"] = $ordersell["goods_price"] * $ordersell["goods_number"];
					
						$ordersell["originsku"] =$rsdb["goods_sku"];
						$ordersell["goods_weight"] = $rsdb["g_weight"];	//单个商品重量

						
						$this->db->insert("db_order_sell",$ordersell);

							

						$rval = "增加商品：增加新商品->".$rsdb["goods_sku"]." 数量->".intval($ordergoodsnoNum[$key])." 销售价->".trim($ordergoodsnoPrice[$key]).$moneyratelist;
						$this->fun->goods_update_log($orderID,$rval,3);	//更新订单信息
					}
					
				}
					
					//重新计算总商品价格
					$this->m->recalculategoodsprice($orderID);
					if ($this->db->trans_status() === FALSE)
					{
						$this->db->trans_rollback();
					}
					else
					{
						$this->db->trans_commit();
					}
					$this->fun->phpalert(4, "", '', "/orderlist/editorder?order_id={$orderID}#mod");
					
			}
		}
		/***********************************
		** 订单详细中删除商品信息
		**
		***************************/
		if($op == 'delordersellgoods')
		{
			$order = $this->input->post('str');
			
			if($order)
			{
				$order = substr($order,0,-1);
				$this->db->trans_begin();
				$godss = $this->fun->getdatabasesdetail("db_order_sell"," AND rec_id in($order)","GROUP_CONCAT(goods_sn) as goods_sn");
			
				$this->db->delete("db_order_sell","rec_id in($order)");
				$orderID = $this->input->post('orderID');
					//重新计算总商品价格
				$this->m->recalculategoodsprice($orderID);
				$rval = "删除商品：商品->".$godss["goods_sn"]." 被删除";
				$this->fun->goods_update_log($orderID,$rval,3);	//更新订单信息
				
			



				if ($this->db->trans_status() === FALSE)
				{
					$this->db->trans_rollback();
				}
				else
				{
					
					$this->db->trans_commit();
				}
				echo json_encode(200);
			}
		}
		/***********************************
		** 订单详细中拆分订单信息
		** ALTER TABLE `db_order_list` ADD `original_order` VARCHAR(100) NULL COMMENT '拆分订单的原始订单号' AFTER `orderweight`;
		***************************/
		if($op =='chatotalgoods')
		{
			$goodsID = $this->input->post('str');
			if($goodsID)
			{
				/***将所选择商品拆分成新的订单*******/
				$order="";
				$orderID = $this->input->post('orderID');
				$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_id = '".$orderID."'");
				$count  = $this->fun->getdatabasesdetail("db_order_list"," AND original_order= '".$order["order_sn"]."'"," count(order_id) as nums");//存在多少个拆分订单
				
				$original_order = $order["order_sn"];
				$nums = $count["nums"]+1;
				//$ordersn = $order["order_sn"]."-".$nums;
				$this->load->library('Amazondata');
				$order["order_sn"] =$this->amazondata->getNo();
				$order["order_source"] = "拆分订单";
				$order["shipping_name"] = "";
				$order["order_status"] = 2;
				$order["shipping_id"] = "";
				$order["shipping_number"] = "";
				$order["tradeid"] = $order['tradeid']."-".$nums;
				$order["original_order"] = $original_order;	//拆分订单后，记录原始订单号，以备还原拆分订单
				unset($order['order_id']);
				$this->db->trans_begin();
				$this->db->insert("db_order_list",$order);
				$neworderID = $this->db->insert_id();
				
				
				
				/******更新商品信息**********/
				if(!$neworderID){
					echo json_encode(201);
					die;
				}
				$goodsID = substr($goodsID,0,-1);
				$godss = $this->fun->getdatabasesdetail("db_order_sell"," AND rec_id in($goodsID)","GROUP_CONCAT(goods_sn) as goods_sn");
				$this->db->update("db_order_sell",array("order_id"=>$neworderID),"rec_id in ($goodsID)");
				$this->m->recalculategoodsprice($neworderID);	//重新计算商品价值
				$this->m->recalculategoodsprice($orderID);	//重新计算原订单商品价值
				$this->db->update("db_order_list",array("order_source"=>'拆分订单'),"order_id=".$orderID);	//原订单修改状态

				$rval = "拆分订单：商品->".$godss["goods_sn"]." 拆分到新订单<a href=\"/orderlist/editorder?order_id=$neworderID\">$ordersn</a>";
				$this->fun->goods_update_log($orderID,$rval,3);	//更新订单信息
				$rval = "拆分订单：商品->".$godss["goods_sn"]." 从订单<a href=\"/orderlist/editorder?order_id=$orderID\">$original_order</a>拆分";
				$this->fun->goods_update_log($neworderID,$rval,3);	//更新订单信息
				
				if ($this->db->trans_status() === FALSE)
				{
					$this->db->trans_rollback();
				}
				else
				{
					$this->db->trans_commit();
				}
				$reat["code"] = 200;
				$reat["txt"] = $neworderID;
				echo json_encode($reat);
				die;

			}
		}

		if($op == 'jsmergeorder')
		{
			/********************************************
			* 合并订单信息
			***********************************************/
			$orderID = $this->input->post('str');
			$orderID = substr($orderID,0,-1);
			$NeworderID = $this->m->jsmergeorder($orderID);
			$reat["code"] = 200;
			$reat["txt"] = $NeworderID;
			echo json_encode($reat);
			die;
		}
		if($op =='batchjsmergeorder')
		{
			/********************************************
			* 批量合并订单信息
			***********************************************/
			$orderID = $this->input->post('str');
			$orderID = substr($orderID,0,-1);
			$orderstr =explode(",",$orderID);
			$NeworderID = array();
			$dates = time()-86400*10;
			foreach($orderstr as $key=>$rs)
			{
				
				$rsdb = $this->fun->getdatabasesdetail("db_order_list"," AND order_id = '".$rs."' ","order_sn, shopid, `consignee`,address ,tel, zipcode");
				if($rsdb){
					$sql = "SELECT GROUP_CONCAT(order_id) as neworderID  FROM `db_order_list` WHERE `consignee` LIKE '" . addslashes($rsdb["consignee"]). "' AND address ='".addslashes($rsdb['address'])."' AND zipcode='".$rsdb['zipcode']."' AND tel='".$rsdb['tel']."' AND shopid='" . $rsdb["shopid"] . "' AND (order_status = 1 or order_status =2) AND order_source ='正常订单' AND dates >='".date("Y-m-d",$dates)."' AND  (country !='china' or country !='japan' or country !='Japan') ";
					$orderMerge = $this->db->get_one($sql);
					if(strstr($orderMerge['neworderID'],","))
					{
						$NeworderID[]= $this->m->jsmergeorder($orderMerge['neworderID']);
					}
				}
			}
			if($NeworderID){
			$orderid = implode(",",$NeworderID);
				$reat["code"] = 200;
				$reat["txt"] = $orderid;
				echo json_encode($reat);
				die;	
			}

			
		}
		if($op == 'selectCountry')
		{
			/********************************************
			* 获取国家信息
			***********************************************/
			$country  = $this->m->getSearchCountry();
			$this->tpl->assign("country",$country);
			if($this->input->get('type')){
				$this->tpl->assign("t",$this->input->get('type'));
			}else{
				$this->tpl->assign("t",0);
			}
			$this->tpl->display("order/countrylist.tpl",0,0,1);
		}
		//通过goods_id查询所有订单信息
		if($op =='showhistoryOrder')
		{
			$goods_id = intval($this->input->get('goods_id'));
			$nowpage = $_REQUEST["pageid"];
			if ($nowpage == "") $nowpage = 1;
			$where = "";
			$starttime = trim($this->input->get('starttime'));
			if ($starttime) {
				$times = $starttime;
				$where .= " AND (B.dates >= '" . $times . "')";
				$this->tpl->assign("starttime", $starttime);
			}
			$endtime = trim($this->input->get('endtime'));
			if ($endtime) {
				$times = $endtime;
				$where .= " AND (B.dates <= '" . $times. "')";
				$this->tpl->assign("endtime", $endtime);
			}

			$other = trim($this->input->get('other'));
			if ($other) {
				$where .= " AND (order_sn = '" . $other. "')";
				$this->tpl->assign("other", $other);
			}

			$status = trim($this->input->get('status'));
			if ($status) {
				$where .= " AND (B.order_status = '" . $status. "')";
				$this->tpl->assign("status", $status);
			}
			
			$orderby = " order by  B.order_id DESC";
			if($this->input->get('if_csv'))
			{
				$if_csv = 1;
			}
			$list = $this->fun->getalllist("db_order_sell A left join db_order_list B on A.order_id=B.order_id", " AND A.goods_id='".$goods_id."' AND B.order_status !=7 AND B.order_status !=6  $where", $nowpage, $if_csv, $this->pageSize, $orderby);
			foreach($list['list'] as $key=>$rs)
			{
				$ordersn = $this->fun->getdatabasesdetail("db_order_batchexpress"," AND batch_order_sn = '".$rs['order_sn']."'");
				$list['list'][$key]["expresstime"] = $ordersn['opertime'];
			}

			$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
			$this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
			$this->tpl->assign("total", $list["total"]);
			$this->tpl->assign("pageList", $pageList);
			$this->tpl->assign("goods_id", $goods_id);
			$this->tpl->assign("orderlist", $list["list"]);
			$this->tpl->display("product/showhistoryOrder.tpl");
		}
		//通过goods_id查询所有日志信息
		if($op =='showhistorylog')
		{
			$goods_id = intval($this->input->get('goods_id'));
			$nowpage = $_REQUEST["pageid"];
			if ($nowpage == "") $nowpage = 1;
			$where = "";
			
			
			$orderby = " order by  id DESC";
			
			$list = $this->fun->getalllist("db_goods_log", " AND types = 1 and goods_id='".$goods_id."' $where", $nowpage, $if_csv, $this->pageSize, $orderby);
			$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
			$this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
			$this->tpl->assign("total", $list["total"]);
			$this->tpl->assign("pageList", $pageList);
			$this->tpl->assign("goods_id", $goods_id);
			$this->tpl->assign("orderlist", $list["list"]);
			$this->tpl->display("product/showhistorylog.tpl");
		}
		if($op == 'selectShop')
		{
			/********************************************
			 * 获取店铺信息
			 ***********************************************/
			$shopname  = $this->m->selectShop();
			$this->tpl->assign("shopname",$shopname);
			$this->tpl->display("order/shoplist.tpl",0,0,1);
		}
		if($op == 'selectZipcode')
		{
			/********************************************
			 * 获取邮编信息
			 ***********************************************/
			$Zipname  = $this->m->selectZipcode();
			$this->tpl->assign("zipname",$Zipname);
			$this->tpl->display("order/ziplist.tpl",0,0,1);
		}
		if($op == 'selectLogistics')
		{
			/********************************************
			 * 获取物流信息
			 ***********************************************/
			$logisticsname  = $this->m->selectLogistics();
			$this->tpl->assign("logisticsname",$logisticsname);
			$this->tpl->display("order/logisticslist.tpl",0,0,1);
		}
		if($op == 'stordersearch')
		{
			/********************************************
			* 搜索脚本停用
			***********************************************/
			$id  = $this->input->get("id");
			$type  = $this->input->get("type");
			$this->db->update("db_order_search",array("status"=>$type),"id=".$id);
			header("location:/order/ordersearchlist");
		}
		if($op == 'stexpresstype')
		{
			$id  = $this->input->get("id");
			$type  = $this->input->get("type");
			$this->db->update("db_order_express",array("status"=>$type),"id=".$id);
			header("location:/order/expresstype");
		}
		if($op == 'delexpress')
		{
			/********************************************
			* 货运配置删除
			***********************************************/
			$id  = $this->input->get("id");
			$this->db->delete("db_order_express","id=".$id);
			header("location:/order/expresstype");
		}
		if($op == 'delsearchorder')
		{
			/********************************************
			* 搜索脚本删除
			***********************************************/
			$id  = $this->input->get("id");
			$this->db->delete("db_order_search","id=".$id);
			header("location:/order/ordersearchlist");
		}

		if($op =='addorderNewgoods')
		{
			/********************************************
			* 创建新订单时创建商品信息
			***********************************************/

			$ordergoodsno  = $this->input->post('ordergoodsno');	//商品SKU
			$ordergoodsnoNum  = $this->input->post('ordergoodsnoNum');	//商品数量
			$ordergoodsnoPrice  = $this->input->post('ordergoodsnoPrice');	//商品价格
			if($ordergoodsno)
			{
				$ordergoodsno = substr($ordergoodsno,0,-1);
				$ordergoodsno = explode(",",$ordergoodsno);

				$ordergoodsnoNum = substr($ordergoodsnoNum,0,-1);
				$ordergoodsnoNum = explode(",",$ordergoodsnoNum);

				$ordergoodsnoPrice = substr($ordergoodsnoPrice,0,-1);
				$ordergoodsnoPrice = explode(",",$ordergoodsnoPrice);
			
			if(count($ordergoodsno)>0)
			{
				$newarray = "";
				foreach($ordergoodsno as $key=>$rs)
				{
					$rsdb = $this->fun->getdatabasesdetail("db_goods"," AND goods_sku = '".$rs."'","goods_id,goods_name,goods_sku");
					if($rsdb){
					$rsdb["nums"] = $ordergoodsnoNum[$key];
					$rsdb["Price"] = $ordergoodsnoPrice[$key];
					$newarray[$key]= $rsdb;
					}
				}
			}
			}
			
			if($newarray)
			{
				echo json_encode($newarray);
				die;
			}
		}
		if($op == 'saveupsexpress')
		{
			/********************************************
			* 订单相关设置中保存upsexpress
			***********************************************/
			$post["comname"]  = $this->input->post("comname");
			$post["attentionname"]  = $this->input->post("attentionname");
			$post["shippernumber"]  = $this->input->post("shippernumber");
			$post["phonenumber"]  = $this->input->post("phonenumber");
			$post["address"]  = $this->input->post("address");
			$post["city"]  = $this->input->post("city");
			$post["postcode"]  = $this->input->post("postcode");
			$post["countrycode"]  = $this->input->post("countrycode");
			$post["password"]  = $this->input->post("password");
			$post["accesskey"]  = $this->input->post("accesskey");
			$post["upsurl1"]  = $this->input->post("upsurl1");
			$post["upsurl2"]  = $this->input->post("upsurl2");
			echo serialize($post);
			die;
		}
		
		if($op == 'getupsexpress')
		{
			/********************************************
			* 订单相关设置中读取upsexpress
			***********************************************/
			$res = $this->fun->getdatabasesdetail("web_config"," AND c_key = '".$this->input->post_get("ckey")."'");
			if($res["c_value"])
			{
				echo json_encode(unserialize($res["c_value"]));
				die;
			}
		}
		
		/********************************************
		* 保存交运信息
		**string type :"UPS";"SF"
		**string orderlist
		***********************************************/
		if($op=='saveexpress'){
			$res = $this->m->saveexpress();
            $expresstype=$this->input->post("type");
            //echo $expresstype;
            if($expresstype=='sfexpress'){
                header("location:/doit/sfexpress/0/0"); die;  
            }elseif($expresstype=='UPS'){
                header("location:/doit/ajaxbutton?op=upsexpress");die;
            }
			if($res)
			{
				//开始自动交运
				header("location:/doit/ajaxbutton?op=upsexpress");
			}
			
		}
		 /*******************************
         *** 自动速卖通无忧物流
         ******************************/
        if($op =='WUYexpress')
        {
			//如果获取到的订单来源为马帮
			if($this->input->post('isformMabang') ==1)
			{
				$this->load->library('Mabang');
				$orderlist = trim($this->input->post('orderlist'));
				
				$wuyconfig=""; 
				$wuyconfig["pickstyle"] = $this->input->post('pickstyle');	//上门揽收或自行配送
				$wuyconfig["kd"] = $this->input->post('kd');	//国内快递
				$wuyconfig["kdnumber"] = $this->input->post('kdnumber');//快递号
				$wuyconfig["Expressqudao"] = $this->input->post('Expressqudao');//线上发货物流
				$wuyconfig["isbattery"] = $this->input->post('isbattery');//是否含电池
				$wuyconfig["UndeliverableDecision"] = $this->input->post('UndeliverableDecision');//不可达处理
				if($wuyconfig){
					$newwuconfig = serialize($wuyconfig);
				}
			
				$res= $this->mabang->savemabangorderlist($orderlist,9,'',$newwuconfig);


			}else{
				$res = $this->m->saveexpress();
			}
			if($res)
			{
				echo "<meta http-equiv=\"refresh\" content=\"1; url=/exportorder/ajaxbutton?op=aliexpresswuliu\">";
			}
        }
		/********************************************
		* 设置预估运费公式
		***********************************************/
		if($op =='savearea1')
		{
			if($this->input->post('types')==2)
			{
				
				$post="";
				$post['title'] = $this->input->post('reserve1');
				$post['expresstypeid'] = $this->input->post('expresstypeid');
				$post['baseweight'] = $this->input->post('baseweight');
				$post['basemoney'] = $this->input->post('basemoney');
				$post['unitweight'] =  $this->input->post('unitweight');
				$post['unitmoney'] = $this->input->post('unitmoney');
				$post['reserve6'] = $this->input->post('reserve6');
				$post['reserve7'] = $this->input->post('reserve7');
				$post['country'] = $this->input->post('country');
				$post['types'] = 2;
				
				$id = intval($this->input->post('formulaID'));
				if($id)
				{
					$this->db->update("db_order_express_formula",$post,"id='".$id."'");
				}else{
					$this->db->insert("db_order_express_formula",$post);
				}
			}else{
			
			$title = $this->input->post('title');
			$country = $this->input->post('country');
			$area = $this->input->post('area');
			$baseweight = $this->input->post('baseweight');
			if(count($baseweight)>0)
			{
				foreach($title as $key=>$rsTitle)
				{
					$this->db->trans_begin();	//事务开始
					$post="";
					$post['title'] = $rsTitle;
					$post['expresstypeid'] = $this->input->post('expresstypeid');
					$post['country'] = $country[$key];
					$post['area'] = $area[$key];
					$post['types'] = 1;

					
					$rsdb = $this->fun->getdatabasesdetail('db_order_express_formula'," AND title='".$rsTitle."' AND expresstypeid='". $this->input->post('expresstypeid')."'");
					if($rsdb)
					{
						$this->db->update("db_order_express_formula",$post,"id='".$rsdb["id"]."'");
						$formula_id = $rsdb["id"];
					}else{
						$this->db->insert("db_order_express_formula",$post);
						$formula_id = $this->db->insert_id();
					}
					foreach($baseweight as $skey=>$rwei)
					{
						$nskye = $skey+1;
						$basemoney = $this->input->post("basemoney$nskye");
						
							$post="";
							$post['formula_id'] = $formula_id;
							$post['weight'] = $rwei;
							$post['price'] = $basemoney[$key]?$basemoney[$key]:0;
							$post['expresstypeid'] = $this->input->post('expresstypeid');
							
							$rsdbst = $this->fun->getdatabasesdetail('db_order_express_formula_price'," AND formula_id='".$formula_id."' AND weight='".$rwei."'");
							if($rsdbst)
							{
								$this->db->update("db_order_express_formula_price",$post,"id='".$rsdbst["id"]."'");
							}else{
								$this->db->insert("db_order_express_formula_price",$post);
							}
							
						
					}
					if ($this->db->trans_status() === FALSE)
					{
						$this->db->trans_rollback();
					}
					else
					{
						$this->db->trans_commit();
					}

				}
			
				}
			}


				
			
			header("location:/order/addexpresstype?id=".$post['expresstypeid']);
		}
		/********************************************
		* 删除预估运费
		***********************************************/
		if($op =='deletearea')
		{
			$id = intval($this->input->post('id'));
			if($id)
			{
				$this->db->delete("db_order_express_formula","id='".$id."'");
			}
			
		}
		if($_REQUEST["op"]=='getcountry')
		{
			$country = trim($this->input->post('country'));
			$rsdb = $this->fun->getdatabasesdetail("d_country"," AND countrynamecn='".$country."'");
			if(!$rsdb)
			{
				echo 201;
				die;
			}else{
				echo 200;
				die;			
			}
		}
		/********************************************
		* 编辑预估运费
		***********************************************/
		if($op =='editarea')
		{
			$id = intval($this->input->post('id'));
			if($id)
			{
				$res = $this->fun->getdatabasesdetail("db_order_express_formula" ," AND id ='".$id."'");
				echo json_encode($res);
			}
			
		}
		
		/********************************
		修改FBA的销售SKU信息
		*************************/
		if($op =='changFBAgoodsno')
		{
			$olddata = trim($this->input->post('olddata'));
			$val = trim($this->input->post('val'));
			$shopid = intval($this->input->post('id'));

			//先添加子SKU信息
			$goods = $this->fun->getdatabasesdetail('db_goods'," AND goods_sku='".$val."'");
			if(!$goods)
			{
				$data["txt"] = "不存在该SKU【{$val}】 信息,请先创建该SKU";
				$data["code"] = "201";
				echo json_encode($data);
				die;
			}
			$postdata= "";

			if(strpos($goods['cognatelist'],$olddata.",") === false){     //使用绝对等于

				if($goods['cognatelist']=='')
				{
					$postdata['cognatelist']  = ",".$olddata.",";
				}else{
					$postdata['cognatelist']  = $olddata.",";
				}
				$postdata['cognatelist'] = $goods['cognatelist'].$postdata['cognatelist'];
				$this->db->query($this->db->update_string("db_goods",$postdata,"goods_id='".$goods['goods_id']."'"));
			}
			//只更新同店铺的销售SKU
			
			$postsell="";
			$postsell['productid'] = $val;
			$postsell['goods_id'] = $goods['goods_id'];
			$postsell['productname'] = $goods['goods_name'];
			$cosprice = $this->fun->get_Goods_costprice($val);
			
			
			
			$orderlist = $this->fun->getdatabaseslist('db_amzordertmpsell'," AND productid='".$olddata."'");
			if(count($orderlist)>0)
			{
				foreach($orderlist as $key=>$rs)
				{
					$isnu = $this->fun->getdatabasesdetail("db_amzordertmp"," and id='".$rs['ordertmpid']."'","shopid,tradeid,dates");
					
					if($isnu['shopid'] == $shopid)
					{
						$postsell['costprice'] = $cosprice*$rs["ordernum"];
						$postsell['goods_weight'] = $goods['g_weight'];
						
						$derprice = $this->fun->getdatabasesdetail("t_overseaproduct"," AND sku = '".$val."'","deliverprice");
						if($derprice['deliverprice']>0){
							$postsell['deliverprice'] =$derprice['deliverprice'];//头程费用
						}
						$this->db->query($this->db->update_string("db_amzordertmpsell",$postsell," productid='".$olddata."' AND ordertmpid  = '".$rs['ordertmpid']."'"));

						$this->fun->goods_stock_log($rs['ordertmpid'],$goods['goods_id'],$isnu['shopid'],$isnu["tradeid"]."-FBA订单",$rs["ordernum"],0,$rs["ordernum"],0,'',1); //更新FBA库存日志

							$isnust = $this->fun->getdatabasesdetail("db_amzordertmpsell"," AND goods_id=0 and ordertmpid='".$rs['ordertmpid']."'","id");
							if(!$isnust)
							{
								$this->db->update("db_amzordertmp",array('status'=>1)," id ='".$rs['ordertmpid']."' AND status=2");

								
								$rval= "FBA订单修正销售SKU：原SKU->$olddata 新SKU->$val";
								$this->fun->goods_update_log($rs['ordertmpid'], $rval, 7);    //日志
							}
					}
				}
			}

			
			//修改所有的FBA销售SKU信息
			
		

			
			$data["txt"] = "更新成功！";
			echo json_encode($data);

		}

		if($op =='changfulflllmentgoodsno')
		{
			print_r($_POST);
			$olddata = trim($this->input->post('olddata'));
			$val = trim($this->input->post('val'));
			$id = intval($this->input->post('id'));
			//先添加子SKU信息
			$goods = $this->fun->getdatabasesdetail('db_goods'," AND goods_sku='".$val."'");
			if(!$goods)
			{
				$data["txt"] = "不存在该SKU【{$val}】 信息,请先创建该SKU";
				$data["code"] = "201";
				echo json_encode($data);
				die;
			}

			$postdata= "";
			if(strpos($goods['cognatelist'],$olddata.",") === false){     //使用绝对等于

				if($goods['cognatelist']=='')
				{
					$postdata['cognatelist']  = ",".$olddata.",";
				}else{
					$postdata['cognatelist']  = $olddata.",";
				}
				$postdata['cognatelist'] = $goods['cognatelist'].$postdata['cognatelist'];
				$this->db->query($this->db->update_string("db_goods",$postdata,"goods_id='".$goods['goods_id']."'"));
			}
			
			$postsell="";
			$postsell['sku'] = $val;
			$postsell['goods_id'] = $goods['goods_id'];
			$this->db->update('db_fba_fulflllment',$postsell,"sku='".$olddata."'");
			$data["code"] = "200";
			$data["txt"] = "更新成功！";
			echo json_encode($data);
		}

		/********************************************
		* 物流中心重新交运失败的信息
		********************************************/
		if($op =='repeatexpress'){
  		    $orderType = intval($this->input->post('orderType'));
            $orderID = $this->input->post('orderID');
			$orderID = substr($orderID,0,-1);
            $shipments=$this->db->get_where('db_mabangorder',"orderType='".$orderType."'AND id in ($orderID)")->result_array();
            $orderdata=array();
            $express_id_arr=array();
            foreach($shipments as $index=>$expressinfo){
                $orderdata[]=$expressinfo['orderID']; 
                $express_id_arr[$expressinfo['orderID']]=$expressinfo['id'];  
            }
            
            $orderdata=implode("','",$orderdata);
            $data = $this->db->get_where("db_order_list","order_sn in ('".$orderdata."')")->result_array();
            foreach($data as $key=>$rs){
                $postdata=array();
				//$postdata["statusst"]=$statustext;
				$postdata["customerid"] = addslashes($rs["consignee"]);
				$postdata["customertype"]= $rs["shopname"];
				$postdata["customertel1"]= $rs["tel"]?$rs["tel"]:$rs["mobile"];
				$postdata["customertel2"]= $rs["mobile"];
				//获取国家标识strtoupper
				$rscountry = $this->fun->getdatabasesdetail("d_country"," AND countrynamecn='".strtoupper(trim($rs["country"]))."'");
				if($rscountry){
					$customerqq = $rscountry["countryid"];
                    $rs["country_code"]= $rs["country_code"]==""?$customerqq:$rs["country_code"];
				}
				$postdata["customerqq"]=  $rs["country_code"];	//国家标识
				$postdata["customercountry"]= $rs["country"];//国家
				if($orderType==2)	//UPS需要获取洲的缩写
				{
					$strprovince = strlen($rs["province"]);
					if($strprovince>3 ||  $rs["province"] =='')
					{
						//自动抓取省code
						$resprovince = $this->fun->getdatabasesdetail("d_country_state"," AND name='".addslashes(trim($rs["province"]))."'");
						$rs["province"] = $resprovince['code'];
					}
				}
				$postdata["customerprovince"]= $rs["province"];
				$postdata["customercity"]= $rs["city"];
				$postdata["customeraddress"]= $rs["address"].$rs["address2"];
				$postdata["customerzipcode"]= $rs["zipcode"];
				$postdata["moneytype"]= $rs["moneytype"];
                $postdata["isexe"] = 0;
				$this->db->update('db_mabangorder', $postdata, 'orderType='.$orderType.' AND id='.$express_id_arr[$rs['order_sn']]);
			
				if($orderType==3 && $this->config->item('isdhlremote')==1)	//如果使用DHL远程交运
				{
					$this->load->library('Expresssend');
					$rsdb = $this->fun->getdatabasesdetail("db_mabangorder",' AND id='.$express_id_arr[$rs['order_sn']]);
                    if(stripos($postdata["customeraddress"],'PO Box')===0){//have error
            			$exememo = "收货地址PO Box位置不够具体";
            			$updateinfo["isexe"] = 2;
                		$updateinfo["exememo"] = $exememo;
                		$updateinfo["mailinstime"] =time();
                		$this->db->query($this->db->update_string('db_mabangorder', $updateinfo, 'id='.$express_id_arr[$rs['order_sn']]));
                    }else{
                        $this->expresssend->saveremotedata($rsdb,$express_id_arr[$rs['order_sn']]);     
                    }
					
				}

                //echo $this->db->last_query();
                //die;
                //$this->db->update('db_mabangorder',$postdata,"orderType='".$orderType."'AND id in ($orderID)");
			}
			$express_type=array(
				1=>'/order/sfexpress?isexe=3',
				2=>'/order/sfexpress/2?isexe=3',
				3=>'/expressshipment/datalist?isexe=3',
				4=>"/expressshipment/datalist/4?isexe=3",
				5=>'/expressshipment/datalist/5?isexe=3',
				6=>'/deliverorder/emsExpress?isexe=3',
				7=>'/deliverorder/emsExpress/7?isexe=3',
				8=>'/deliverorder/emsExpress/8?isexe=3',
				9=>'/deliverorder/aliexpressOrder?isexe=3',
				10=>'/expressshipment/datalist/10?isexe=3',
				11=>'/deliverorder/emsExpress/11?isexe=3',
				13=>'/deliverorder/emsExpress/13?isexe=3',
                14=>'/expressshipment/datalist/14?isexe=3',
                12=>'/expressshipment/datalist/12?isexe=3');

			echo $express_type[$orderType];
			die;
		}

		if($op =='deleteorder')
		{
			$orderstr = $this->input->post('str');
			$id = substr($orderstr,0,-1);
			$inid = explode(",",$id);
			foreach($inid as $key=>$orderSN)
			{
				$res = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn = '".trim($orderSN)."' AND order_status=6");
				if($res)
				{
					$this->db->delete("db_order_list","order_id=".$res['order_id']);
					$this->db->delete("db_order_sell","order_id=".$res['order_id']);
					$this->db->delete("db_goods_log"," types=3 and goods_id=".$res['order_id']);
				}
			}
			echo 200;
			die;
		}
		//从货运列表
		if($op =='doImportexpress')
		{
			require_once BASEPATH.'../fuman/ClassesExcel/PHPExcel/IOFactory.php';
			$res = $this->fun->newupfile('file_excel','product');
			$upfile =BASEPATH.'../uploads/'.$res['pic'];
			if(!file_exists($upfile))
			{
				echo "没找到文件->". $upfile;
				die;
			}
			$this->m->ImportNewexpress($upfile);
			echo "OK";

		}
		/********************************************
		* 查看扫单发货列表
		********************************************/
		if($op == 'scanorderlist')
		{
			$nowpage = $_REQUEST["pageid"];
			if ($nowpage == "") $nowpage = 1;
			$where = "";
			$starttime = trim($this->input->get('starttime'));
			if ($starttime) {
				$times = $starttime . " 00:00:00";
				$where .= " AND (opertime >= '" . $times . "')";
				$this->tpl->assign("starttime", $starttime);
			}
			$endtime = trim($this->input->get('endtime'));
			if ($endtime) {
				$times = $endtime . " 23:59:59";
				$where .= " AND (opertime <= '" . $times. "')";
				$this->tpl->assign("endtime", $endtime);
			}

			$other = trim($this->input->get('other'));
			if ($other) {
				$where .= " AND (batch_order_sn = '" . $other. "' or batch_shipping_number = '" . $other. "')";
				$this->tpl->assign("other", $other);
			}
			$kw = trim($this->input->get('kw'));
			if ($kw) {
				$where .= " AND (oper = '" . $kw. "')";
				$this->tpl->assign("kw", $kw);
			}
	
			$orderby = " order by id desc";
			if($this->input->get('if_csv'))
			{
				$if_csv = 1;
			}
			$list = $this->fun->getalllist("db_order_batchexpress", $where, $nowpage, $if_csv, $this->pageSize, $orderby);
			
			 if ($if_csv) {
				$filename = date('YmdHis') . '.csv';
				header("Content-type: text/csv");
				header("content=text/html;charset=utf8");
				header("Content-Disposition: attachment; filename=" . $filename);
				header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
				header('Expires:0');
				header('Pragma:public');
				$str = "订单编号,运单编号,扫重,物流方式,扫单员,扫单时间,收件人,地址,电话,城市,国家\r\n";
				$pattern = '/(,)+/i';
				  foreach ($list["list"] as $v) {
					  $order = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn = '".$v["batch_order_sn"]."'");
					$order["consignee"] = preg_replace($pattern,'，',$order["consignee"]);
					$order["address"] = preg_replace($pattern,'，',$order["address"]);
				
					$str .= "" . $v["batch_order_sn"].",".$v["batch_shipping_number"].",".$v["batch_orderweight"]."," . $v["batch_shipping_name"]."," . $v["oper"].",".$v["opertime"]."," . $order["consignee"]."," . $order["address"]."," . $order["tel"]."," . $order["city"]."," . $order["country"]."\r\n";
				  }
				  echo mb_convert_encoding($str, "cp936", "UTF-8");
				  exit();
			 }

				/*
					if($this->input->get('if_csv'))
					{
						$headers =array("订单编号","运单编号","扫重","物流方式","扫单员","扫单时间","处理结果","收件人","地址","电话","城市","国家","邮编","省");
						foreach($list["list"] as $key=>$rs)
						{
							$listdata[$key][] = $rs["batch_order_sn"]; 
							$listdata[$key][] = $rs["batch_shipping_number"]; 
							$listdata[$key][] = $rs["batch_orderweight"]; 
							$listdata[$key][] = $rs["batch_shipping_name"]; 
							$listdata[$key][] = $rs["oper"]; 
							$listdata[$key][] = $rs["opertime"]; 
							$listdata[$key][] = '处理成功'; 

							$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn = '".$rs["batch_order_sn"]."'");
							$listdata[$key][] = $order['consignee']; 
							$listdata[$key][] = $order['address'].$order['address2']; 
							$listdata[$key][] =  $order['tel']; 
							$listdata[$key][] = $order['city']; 
							$listdata[$key][] = $order['country']; 
							$listdata[$key][] = $order['zipcode']; 
							$listdata[$key][] = $order['province']; 

					  }
						$this->fun->ouputexclePro($headers,$listdata);
					}
				*/
			$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
			$this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
			$this->tpl->assign("total", $list["total"]);
			$this->tpl->assign("pageList", $pageList);
			$this->tpl->assign("orderlist", $list["list"]);
			$this->tpl->display("order/scanorderlist.tpl");
		}
		/******保存鞋子尺码*****/
		if($op =='saveshoesSize')
		{
			$this->m->saveshoseSize();
			echo 200;
			die;
		}

		/********************************************
		* 导出扫单发货列表
		********************************************/
		if($op =='outexpressexcel')
		{
			$types = $this->input->get('types');
			$times = "2017-09-27 00:00:00";
			$endtime = date("Y-m-d")." 23:59:59";
			$isoutput = time();
			$orderlist = $this->fun->getdatabaseslist('db_order_batchexpress'," AND batch_shipping_name='".$types."' AND opertime >='".$times."' and opertime <='".$endtime."' AND is_output=0");
			if($types=='ups')
			{
				$ups = stripslashes($this->config->item("upsexpressset"));
			    $ups = unserialize($ups);
				$headers =array("center","hawb","service","type","pcs","weight","shipperaccount","shipper","shipper_eng","shipperadd","shippercontact","shippertel","consignee","consigneeadd","consigneecontact","consigneetel","country","goods","quantity","unit","value","currency","postcode","hs","company","package","ctino","unit1");
				$listdata = "";
				foreach($orderlist as $key=>$rs)
				{
					$rsdb = $this->db->get_one("SELECT * from db_mabangorder where orderID='".$rs['batch_order_sn']."' AND orderType=2 and isexe=1");

					$listdata[$key][] = 'JD';
					$listdata[$key][] = $rs['batch_shipping_number'];
					$listdata[$key][] = 1;
					$listdata[$key][] = 'C';
					$listdata[$key][] = '1';
					$listdata[$key][] = round($rs['batch_orderweight']/1000,3);
					$listdata[$key][] = 'WY3000';
					$listdata[$key][] = '上海漫创商贸有限公司';
					$listdata[$key][] = 'SHANGHAI MANCHUANG TRADING CO.,LTD';
					$listdata[$key][] = strtoupper($ups['address']);
					$listdata[$key][] = strtoupper($ups['attentionname']);
					$listdata[$key][] = $ups['phonenumber'];
					$listdata[$key][] = strtoupper($rsdb['customerid']);
					$listdata[$key][] = strtoupper($rsdb['customeraddress']);
					$listdata[$key][] = strtoupper($rsdb['customerid']);
					$listdata[$key][] = $rsdb['customertel1']?$rsdb['customertel1']:$rsdb['customertel2'];
					$listdata[$key][] = $rsdb['customerqq'];
					$listdata[$key][] = 'COSTUME SAMPLE';
					$listdata[$key][] = 1;
					$listdata[$key][] = 'PCS';
					$listdata[$key][] = '21.00';
					$listdata[$key][] = 'USD';
					$listdata[$key][] = $rsdb['customerzipcode'];
					$listdata[$key][] = '61032300';
					$listdata[$key][] = '';
					$listdata[$key][] = '';
					$listdata[$key][] = '';
					$listdata[$key][] = '';
					$this->db->update('db_order_batchexpress',array("is_output"=>$isoutput)," id=".$rs['id']);
				}
				
				$this->fun->ouputexclePro($headers,$listdata);
			}

		}
		
	}
    
	public function sfexpress($orderType=1)
	{
        $get_express_type=dhtml($_GET['orderType']);
        if(!empty($get_express_type)){
            $orderType=$get_express_type;    
        }
		$nowpage = $_REQUEST["pageid"];
	    if ($nowpage == "")
            $nowpage = 1;
		
		$where = " and orderType =".$orderType;
		$isexe = $this->input->get('isexe');
		$this->tpl->assign("isexe",$isexe);
		if($isexe==3){
			$where.=" AND isexe = 0";
		}else{
			if(!$isexe){
			}else{
			$where.=" AND isexe = $isexe";
			}
		}
		$other = trim($this->input->get('other'));
		if($other)
		{
			$where.=" AND (orderID = '".$other."' or mailNo = '".$other."')";
			$this->tpl->assign("other",$other);
		}

//		$isexe = trim($this->input->get('isexe'));
//		if($isexe)
//		{
//			$where.=" AND (isexe = '".$isexe."')";
//			$this->tpl->assign("isexe",$isexe);
//		}

		$starttime = trim($this->input->get('starttime'));
		if($starttime)
		{
			$times = $starttime." 00:00:00";
			$where.=" AND (mailinstime >= '".strtotime($times)."')";
			$this->tpl->assign("starttime",$starttime);
		}

		$endtime = trim($this->input->get('endtime'));
		if($endtime)
		{
			$times = $endtime." 23:59:59";
			$where.=" AND (mailinstime <= '".strtotime($times)."')";
			$this->tpl->assign("endtime",$endtime);
		}
		$statusst = trim($this->input->get('statusst'));
		if($statusst)
		{
			if($statusst==1)
			{
				$status ='已支付';
			}
			if($statusst==2)
			{
				$status ='配货中';
			}
			if($statusst==3)
			{
				$status ='已完成';
			}
			$where.=" AND statusst = '".$status."'";
			$this->tpl->assign("statusst",$statusst);
		}
		$list = $this->fun->getalllist('db_mabangorder',$where,$nowpage,$if_csv,$this->pageSize);

		foreach($list["list"] as $key=>$rs)
		{
			if($rs["mailinstime"])$list["list"][$key]["mailinstime"] = date("Y-m-d H:i:s",$rs["mailinstime"]);
		}
		
		$pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
		$this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
		$this->tpl->assign("department", $_COOKIE["department"]);
		$this->tpl->assign("orderlist",$list["list"]);
        $express_type=array(1=>'顺丰',3=>'DHL',4=>"CNE",5=>'UBI',6=>'云图',7=>'燕文',8=>'EMS');
        $this->tpl->assign('expressType',$express_type[$orderType]);
		$this->tpl->assign("orderType",$orderType);
		if($orderType==2)
		{
		  $this->tpl->display("order/upsexpress.tpl");

		}else
		{
		  $this->tpl->display("order/sfexpress.tpl");
		}	
	}
   
}
